package com.modudf.web.servlet.maskInfoServlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.modudf.common.XML2BeanUtils;
import com.modudf.domain.ResultInfo;
import com.modudf.exception.XMLConvertException;
import com.modudf.service.MaskInfoManagerImpl;

public class DeleteMaskInfoServlet extends HttpServlet {

	private static final long serialVersionUID = 5896669913952204624L;
	private static final Log log = LogFactory.getLog(DeleteMaskInfoServlet.class);

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String mid = request.getParameter("mid");
		ResultInfo result;
		if (mid == null || mid.length() == 0) {
			result = new ResultInfo(-1, "id不能为空");
		} else {
			try{
				MaskInfoManagerImpl.getInstance().deleteMaskInfo(Integer.parseInt(mid));
				result = new ResultInfo();
			}catch (Exception e) {
				result = new ResultInfo(-1, e.getMessage());
				log.fatal(e);
			}
		}
		PrintWriter out = response.getWriter();
		try {
			out.println(XML2BeanUtils.bean2XmlString(result));
		} catch (XMLConvertException e) {
			e.printStackTrace();
		}
		out.close();
	}
}
